//
//  KSNavigationController.m
//  BasketBallLeagues
//
//  Created by kenshin on 4/23/17.
//  Copyright © 2017 kenshin. All rights reserved.
//

#import "KSNavigationController.h"

@interface KSNavigationController ()<UIGestureRecognizerDelegate, UINavigationControllerDelegate>

@end

@implementation KSNavigationController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.interactivePopGestureRecognizer.delegate = self;
    self.interactivePopGestureRecognizer.enabled = NO;
    self.delegate = self;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

+ (void)setNavigationBarAppearance
{
    [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor], NSFontAttributeName:[UIFont systemFontOfSize:18]}];
    [[UINavigationBar appearance] setBarTintColor:[UIColor jc_colorWithHexString:@"#ffffff"]];
    [[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
    UIImage *image = [UIImage jc_createImageWithColor:[UIColor jc_colorWithHexString:@"#ffffff"]];
    [[UINavigationBar appearance] setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
    UIImage *shadowImage = [UIImage jc_createImageWithColor:[BLColorConfig lineColor]];
    [[UINavigationBar appearance] setShadowImage:shadowImage];
    [[UINavigationBar appearance] setTranslucent:NO];
    [UINavigationBar appearance].layer.masksToBounds = NO;
    
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.viewControllers.count >= 1) {
        viewController.hidesBottomBarWhenPushed = YES;
        [viewController ks_setupLeftBackBarButtonItem];
    }
    [super pushViewController:viewController animated:animated];
}

- (BOOL)shouldAutorotate
{
    return NO;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleDefault;
}

#pragma mark - UINavigationControllerDelegate

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.noPopGestureRecognizer) {
        self.interactivePopGestureRecognizer.enabled = NO;
        return;
    }
    if (navigationController.viewControllers.count > 1) {
        self.interactivePopGestureRecognizer.enabled = YES;
    } else {
        self.interactivePopGestureRecognizer.enabled = NO;
    }
}

#pragma mark - UIGestureRecognizerDelegate

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}

@end
